<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>修改药品信息</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <link rel="stylesheet" href="../../lib/layui-v2.6.3/css/layui.css" media="all">
  <link rel="stylesheet" href="../../css/public.css" media="all">
  <script src="../../lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
  <script src="../../lib/jquery-3.4.1/jquery-3.4.1.min.js"></script>
</head>
<body>
<div class="layuimini-container">
  <div class="layuimini-main">
    <form class="layui-form" action="" lay-filter="example">
      <!--            输入框 可以设置type="hidden" 隐藏，外界看不见，但是可以提交数据 -->
      <input name="id" type="hidden" class="layui-input">
      <div class="layui-form-item">
        <label class="layui-form-label">药品名称：</label>
        <div class="layui-input-block">
          <input name="name" lay-verify="title" autocomplete="off" placeholder="请输入药品名称" class="layui-input">
        </div>
      </div>
      <div class="layui-form-item">
        <label class="layui-form-label">供货单位ID:</label>
        <div class="layui-input-block">
          <input name="suid" lay-verify="title" autocomplete="off" placeholder="请输入药品供货单位ID" class="layui-input">
        </div>
      </div>
      <div class="layui-form-item">
        <label class="layui-form-label">经办人ID:</label>
        <div class="layui-input-block">
          <input name="agid" lay-verify="title" autocomplete="off" placeholder="请输入药品经办人ID" class="layui-input">
        </div>
      </div>
      <div class="layui-form-item">
        <label class="layui-form-label">库房ID:</label>
        <div class="layui-input-block">
          <input name="whid" lay-verify="title" autocomplete="off" placeholder="请输入药品库房ID" class="layui-input">
        </div>
      </div>
      <div class="layui-form-item">
        <label class="layui-form-label">计量单位ID:</label>
        <div class="layui-input-block">
          <input name="unid" lay-verify="title" autocomplete="off" placeholder="请输入药品计量单位ID" class="layui-input">
        </div>
      </div>
      <div class="layui-form-item">
        <label class="layui-form-label">产地ID:</label>
        <div class="layui-input-block">
          <input name="arid" lay-verify="title" autocomplete="off" placeholder="请输入药品产地ID" class="layui-input">
        </div>
      </div>
      <div class="layui-form-item">
        <label class="layui-form-label">药品类型ID:</label>
        <div class="layui-input-block">
          <input name="typeid" lay-verify="title" autocomplete="off" placeholder="请输入类型ID" class="layui-input">
        </div>
      </div>
      <div class="layui-form-item">
        <label class="layui-form-label">药品库存：</label>
        <div class="layui-input-block">
          <input name="num" lay-verify="title" autocomplete="off" placeholder="请输入药品库存" class="layui-input">
        </div>
      </div>
      <div class="layui-form-item">
        <label class="layui-form-label">药品批号：</label>
        <div class="layui-input-block">
          <input name="batch" lay-verify="title" autocomplete="off" placeholder="请输入药品批号" class="layui-input">
        </div>
      </div>
      <div class="layui-form-item">
        <label class="layui-form-label">药品售价：</label>
        <div class="layui-input-block">
          <input name="prive" lay-verify="title" autocomplete="off" placeholder="请输入药品售价" class="layui-input">
        </div>
      </div>
      <div class="layui-form-item">
        <label class="layui-form-label">生产日期：</label>
        <div class="layui-input-block">
          <input name="producedate" id="createdate" lay-verify="title" class="layui-input" placeholder="请输入药品生产日期">
        </div>
      </div>


      <div class="layui-form-item">
        <label class="layui-form-label">过期日期：</label>
        <div class="layui-input-block">
          <input name="validdate" id="deletedate" lay-verify="title" class="layui-input"  placeholder="请输入药品过期时间">
        </div>
      </div>


      <div class="layui-form-item">
        <div class="layui-input-block">
          <button class="layui-btn" lay-submit lay-filter="demo1">修改药品信息</button>
          <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
      </div>
    </form>
  </div>
</div>

<script src="lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script src="js/jquery-3.6.0.min.js" charset="utf-8"></script>
<!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->
<script>
  layui.use(['form','laydate'], function () {
    var form = layui.form
            , layer = layui.layer
            , laydate1 = layui.laydate
            , laydate2 = layui.laydate;
    //日期

    laydate1.render({
      elem: '#createdate'
    });
    laydate2.render({
      elem: '#deletedate'
    });

    //监听提交
    form.on('submit(demo1)', function (data) {
      console.log(data.field);
      //ajax 调用接口 修改
      $.post("/api/drugstore/update.do",data.field,function(res){
        if(res.code==200){
          //修改成功
          layer.msg('修改成功！');
          //关闭当前页面
          var iframeIndex = parent.layer.getFrameIndex(window.name);
          parent.layer.close(iframeIndex);
          location.href = "drugstorelist.html"
        }else{
          //修改失败
          layer.msg('修改失败！');
        }
      });
      return false;
    });
    //获取要编辑的内容
    var json=localStorage.getItem("pharmacy");
    console.log(json);
    //表单初始赋值
    form.val('example',eval("("+json+")"));
  });
</script>
</body>
</html>